<template>
	<view>
		<view class="p-20">
			<view class="pt-20 pb-20 pl-40 pr-40 border-radius bg-white flex space-between">
				<view>
					<view class="flex">
						<view class="font-bold mr-20">{{userInfo.username}}</view>
						<uni-icons type="compose" size="22" @click="$goRoute.goUrl('/pages/apply/apply')"></uni-icons>
					</view>
					<view class="font-24 mt-20">工作{{calculateAge(userInfo.workTime)}}年 ·
						{{calculateAge(userInfo.birthday)}}岁
					</view>
				</view>
				<image src="../../static/images/avatar.png" mode=""
					style="width: 100rpx;height: 100rpx;border-radius: 50%;"></image>
			</view>
		</view>
		<view class="pl-20 pr-20 pb-20">
			<view class="pt-20 pb-20 pl-40 pr-40 border-radius bg-white">
				<view class="flex">
					<view class="font-26 font-bold mr-20">个人优势</view>
					<uni-icons type="compose" size="22" @click="$goRoute.goUrl('/pages/apply/apply')"></uni-icons>
				</view>
				<view class="mt-20 font-24">{{userInfo.selfIntroduction}}</view>
			</view>
		</view>
		<view class="pl-20 pr-20 pb-20">
			<view class="pt-20 pb-20 pl-40 pr-40 border-radius bg-white flex space-between">
				<view class="flex">
					<view class="font-26 font-bold">求职状态</view>
				</view>
				<view class="flex items-center">
					<view class="font-24 font-grey mr-20">
						<picker @change="bindPickerChange" :value="userInfo.applyStatus" :range="array">
							<view class="uni-input">{{array[userInfo.applyStatus]}}</view>
						</picker>
					</view>
					<uni-icons custom-prefix="iconfont" type="icon-xiangyou1" size="12"
						@click="$goRoute.goUrl('/pages/apply/apply')"></uni-icons>
				</view>
			</view>
		</view>
		<view class="pl-20 pr-20 pb-20">
			<view class="pt-20 pb-20 pl-40 pr-40 border-radius bg-white">
				<view class="flex space-between">
					<view class="font-26 font-bold">求职意向</view>
					<uni-icons type="plus-filled" size="22"
						@click="$goRoute.goUrl('/pages/apply/intention?applyuserId='+userInfo.id)"></uni-icons>
				</view>
				<view class="mt-20" v-for="(item, index) in intentionLists" :key="index"
					@click="goEdit('/pages/apply/intention?applyuserId='+userInfo.id, item)">
					<view class="flex space-between flex-align-end">
						<view class="font-26">{{item.expectPosition}}</view>
						<view class="flex">
							<view class="font-20">{{item.expectPayLow}}-{{item.expectPayHigh}}</view>
						</view>
					</view>
					<view class="font-24 font-grey mt-10">{{item.expectCity}} · {{item.expectProfession}}</view>
				</view>
			</view>
		</view>
		<view class="pl-20 pr-20 pb-20">
			<view class="pt-20 pb-20 pl-40 pr-40 border-radius bg-white">
				<view class="flex space-between">
					<view class="font-26 font-bold">工作经历</view>
					<uni-icons type="plus-filled" size="22"
						@click="$goRoute.goUrl('/pages/apply/work?applyuserId='+userInfo.id)"></uni-icons>
				</view>
				<view class="mt-20" v-for="(item, index) in workLists" :key="index"
					@click="goEdit('/pages/apply/work?applyuserId='+userInfo.id, item)">
					<view class="flex space-between flex-align-end">
						<view class="font-26">{{item.companyName}}</view>
						<view class="flex">
							<view class="font-20 font-grey">{{item.startTime}}-{{item.endTime}}</view>
						</view>
					</view>
					<view class="font-24 font-grey mt-10">{{item.profession}} · {{item.position}}</view>
					<view class="font-22 font-grey mt-20">{{item.workInfo}}</view>
				</view>
			</view>
		</view>
		<view class="pl-20 pr-20 pb-20">
			<view class="pt-20 pb-20 pl-40 pr-40 border-radius bg-white">
				<view class="flex space-between">
					<view class="font-26 font-bold">项目经历</view>
					<uni-icons type="plus-filled" size="22"
						@click="$goRoute.goUrl('/pages/apply/project?applyuserId='+userInfo.id)"></uni-icons>
				</view>
				<view class="mt-20" v-for="(item, index) in projectLists" :key="index"
					@click="goEdit('/pages/apply/project?applyuserId='+userInfo.id,item)">
					<view class="flex space-between flex-align-end">
						<view class="font-26">{{item.name}}</view>
						<view class="flex">
							<view class="font-20 font-grey">{{item.startTime}}-{{item.endTime}}</view>
						</view>
					</view>
					<view class="font-24 font-grey mt-10">{{item.role}}</view>
					<view class="font-22 font-grey mt-20">{{item.info}}</view>
				</view>
			</view>
		</view>
		<view class="pl-20 pr-20 pb-20">
			<view class="pt-20 pb-20 pl-40 pr-40 border-radius bg-white">
				<view class="flex space-between">
					<view class="font-26 font-bold">教育经历</view>
					<uni-icons type="plus-filled" size="22"
						@click="$goRoute.goUrl('/pages/apply/education?applyuserId='+userInfo.id)"></uni-icons>
				</view>
				<view class="mt-20" v-for="(item, index) in educationLists" :key="index"
					@click="goEdit('/pages/apply/education?applyuserId='+userInfo.id, item)">
					<view class="flex space-between flex-align-end">
						<view class="font-26">{{item.name}}</view>
						<view class="flex">
							<view class="font-20 font-grey">{{item.startTime}}-{{item.endTime}}</view>
						</view>
					</view>
					<view class="font-24 font-grey mt-10">{{item.education}}</view>
					<view class="font-22 font-grey mt-20">{{item.info}}</view>
				</view>
			</view>
		</view>

		<view class="pl-20 pr-20 pb-20">
			<view class="pt-20 pb-20 pl-40 pr-40 border-radius bg-white">
				<view class="flex space-between">
					<view class="font-26 font-bold">资格证书</view>
					<uni-icons type="plus-filled" size="22"
						@click="goEdit('/pages/apply/credential?applyuserId='+userInfo.id, credentialLists)"></uni-icons>
				</view>
				<view class="flex flex-wrap items-center">
					<view class="mt-20 mr-20" v-for="(item, index) in credentialLists" :key="index" @click="goEdit('/pages/apply/credential?applyuserId='+userInfo.id, credentialLists)">
						<image :src="imgUrl+ item.credential" mode="" style="width: 100rpx;height: 100rpx;">
						</image>
					</view>
				</view>
			</view>
		</view>

		<view class="bottom-view">
			<view class="bottom-btn font-white bg-g" @click="submit">保存</view>
		</view>
	</view>
</template>

<script>
	import {
		getInfo,
		edit
	} from '../../api/apply_user';
	import {
		list as workList
	} from '../../api/apply_work.js';
	import {
		list as projectList
	} from '../../api/apply_project.js';
	import {
		list as educationList
	} from '../../api/apply_education.js';
	import {
		list as intentionList
	} from '../../api/apply_intention.js';
	import {
		list as credentialList
	} from '../../api/apply_credential.js';
import { BASE_URL } from '../../utils/constant';
	export default {
		data() {
			return {
				array: ['离职-随时到岗', '在职-月内到岗', '在职-考虑机会', '在职-随时到岗'],
				index: 0,
				userInfo: {},
				workLists: {},
				projectLists: {},
				educationLists: {},
				intentionLists: {},
				credentialLists: {},
				imgUrl: BASE_URL+ '/jeecg-boot/sys/common/static/'
			};
		},
		onShow() {
			this.getDetail()
		},
		methods: {
			goEdit(url, item) {
				uni.setStorageSync('info', item)
				this.$goRoute.goUrl(url)
			},
			getOther(id) {
				workList({
					id: id
				}).then(res => {
					this.workLists = res.result
				})
				projectList({
					id: id
				}).then(res => {
					this.projectLists = res.result
				})
				educationList({
					id: id
				}).then(res => {
					this.educationLists = res.result
				})
				intentionList({
					id: id
				}).then(res => {
					this.intentionLists = res.result
				})
				credentialList({
					id: id
				}).then(res => {
					this.credentialLists = res.result
				})
			},
			calculateAge(birthdate) {
				var today = new Date();
				var birthDate = new Date(birthdate);
				var age = today.getFullYear() - birthDate.getFullYear();
				var monthDiff = today.getMonth() - birthDate.getMonth();

				if (monthDiff < 0 || (monthDiff === 0 && today.getDate() < birthDate.getDate())) {
					age--;
				}

				return age;
			},
			getDetail() {
				const _this = this
				getInfo().then(res => {
					if (res.code === 200) {
						this.userInfo = res.result
						this.getOther(this.userInfo.id)
					} else {
						this.$tips.showModal('请先填写个人基本信息', () => {
							_this.$goRoute.goUrl('/pages/apply/apply')
						}, () => {
							uni.navigateBack()
						})
					}
				})
			},
			bindPickerChange: function(e) {
				console.log('picker发送选择改变，携带值为', e.detail.value)
				this.userInfo.applyStatus = e.detail.value
				edit({
					id: this.userInfo.id,
					applyStatus: e.detail.value
				})
			},
			submit() {
				const _this = this
				this.$tips.showModal('是否提交保存？', () => {
					_this.$tips.showConfirmModal('提交成功，请等待审核', () => {})
				})
			}
		}
	}
</script>

<style lang="less">
	page {
		background-color: #f6f6f6;
		padding-bottom: 200rpx;
	}

	.bottom-view {
		width: 100vw;
		padding: 40rpx 0;
		background-color: #fff;
		position: fixed;
		bottom: 0;
		left: 0;
		z-index: 99999;
		border-top: 1px solid #efefef;

		.bottom-btn {
			width: 80vw;
			margin: auto;
			text-align: center;
			border-radius: 50rpx;
			padding: 20rpx 0;
		}
	}
</style>